package com.withmiku.world.user.service.impl;

import com.withmiku.world.user.entity.User;
import com.withmiku.world.user.repository.UserRepository;
import com.withmiku.world.user.service.AdminUserService;
import com.withmiku.world.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service("adminUserServiceImpl")
public class AdminUserServiceImpl implements AdminUserService {
    private final UserService userService;
    private final UserRepository userRepository;

    @Autowired
    public AdminUserServiceImpl(@Qualifier("userServiceImpl") UserService userService, UserRepository userRepository) {
        this.userService = userService;
        this.userRepository = userRepository;
    }

    /**
     * 更新用户状态（封禁或解禁）
     */
    @Override
    public void updateStatus(Long id, Integer status) {
        User user = userRepository.findById(id)
                .orElseThrow(() -> new RuntimeException("用户不存在"));
        user.setStatus(status);
        userRepository.save(user);
    }

    @Override
    public User register(String username, String rowPassword, String email) {
        return userService.register(username, rowPassword, email);
    }

    @Override
    public String login(String username, String rowPassword) {
        return userService.login(username, rowPassword);
    }

    @Override
    public User findByUsername(String username) {
        return userService.findByUsername(username);
    }

    @Override
    public void updateAvatar(String username, String avatarUrl) {
        userService.updateAvatar(username, avatarUrl);
    }

    @Override
    public void updateProfile(String username, User newInfo) {
        userService.updateProfile(username, newInfo);
    }

    @Override
    public User findById(Long userId) {
        return userService.findById(userId);
    }
}
